-
Notifications
You must be signed in to change notification settings - Fork 157
feat: support for routes defined in the api #3990
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
3996dfb to
b150c55
Compare
aa6b07e to
712bff9
Compare
4a06218 to
2a15f80
Compare
Overview
|
2a15f80 to
9da2f78
Compare
9da2f78 to
5e36596
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request adds comprehensive API routes functionality to Lagoon, enabling users to manage routing configurations through the API instead of solely via YAML files. This is a beta feature that introduces database-backed route management with support for various route types, alternative domains, annotations, and path-based routing.
Key changes include:
- New GraphQL API endpoints for CRUD operations on routes
- Database schema additions with new
routes,routes_alternate_domain, androutes_annotationstables - Keycloak permission setup for route management
- Integration with active/standby environment switching
- Test suite additions for API route functionality
Reviewed Changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated 13 comments.
Show a summary per file
| File | Description |
|---|---|
| services/api/src/typeDefs.js | Adds GraphQL schema definitions for Route types, mutations, and queries |
| services/api/src/resources/routes/resolvers.ts | Implements route CRUD operations and field resolvers |
| services/api/src/resources/routes/sql.ts | Database query builders for route operations |
| services/api/src/resources/routes/helpers.ts | Helper functions for route management and path route manipulation |
| services/api/database/migrations/20250925000000_routes.js | Database migration for routes tables and related columns |
| services/keycloak/startup-scripts/00-configure-lagoon.sh | Configures Keycloak permissions for route operations |
| services/keycloak/lagoon-realm-base-import.json | Adds route resource and permissions to Keycloak realm |
| node-packages/commons/src/tasks.ts | Handles route configuration in build/deploy tasks |
| services/actions-handler/handler/controller_tasks.go | Updates active/standby routes after environment switches |
| tests/tests/api-routes/ | Test suite for API routes functionality |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
1259b8d to
cc41e10
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 26 out of 26 changed files in this pull request and generated 9 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
c1c2e46 to
fb85fcd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes all make sense.
This reverts commit 9947db6.
General Checklist
Database Migrations
Description
Routes defined in the API
This feature adds the ability to add routes to a project, and then associate that route to an environment. This allows users to add and remove routes without needing to modify their
.lagoon.ymlfiles.If a route defined in the API also exists in the
.lagoon.ymlfile, the route in the API will be used, and the one in the.lagoon.ymlfile will have changes merged on top of the existing configuration (this is handled during the deployment phase). In most cases, the route in the API will have all the required information when sent from the API, which will override whatever was defined in the.lagoon.ymlif there is an existing matching route.To take advantage of routes in the API, a route will need to firstly be created in the project. When creating a route, you can either create it in an attached or unattached state.
If an environment already exists with an appropriate service, you can add the environment and service to the route at creation time, this would be an attached route. You can create a route without having an environment or service defined, this can be useful if an environment doesn't exist yet.
Once a route is added to a project and attached to an environment, a deployment will need to take place to apply the route in the cluster. Without a deployment taking place, the route will not be used.
Advanced features
There are some more advanced features with routes in the API. These are
Active / Standby
Active / Stanby environments when using routes in the API become significantly easier to use. Prior to routes in the API, the routes used would need to be defined in both environment
.lagoon.ymlfiles. This added some complexity to what is otherwise a relatively simple feature.With routes in the API, if the project is configured to have a standby production environment, when creating a route you can select if the route be created as an active or standby route and assign it to the necessary environment. You don't need to define it in both environments anymore, when deploying the environments, the API knows which routes it needs to deploy with. When the active/standby switch occurs, the routes get moved in the API to reflect the environment they were moved to accordingly.
Additionally, you can add normal routes to your active/standby environments that are not flagged as active or standby, these will remain attached to the environment during a switch. These can be useful for ensuring you have a route that will always point to an intended environment.
If using routes in the API and the active/standby feature, it is recommended that you remove the
production_routesconfigurations for active/standby from your.lagoon.ymlfiles and only define the routes in the API. Using both API and.lagoon.ymlroutes at the same time could result in unexpected issues.Additional domains
Additional domains are a way to add more than 1 domain to a route. One way these would be used is if you have a primary domain, eg
example.com, you could addwww.example.comas an additional domain to the route. In kubernetes, this will result in a single ingress with multiple host entries, and if LetsEncrypt certificates are used, those domains will be on the same certificate.This has a hard coded limit of 25 additional domains per route, because LetsEncrypt and potentially others may have different limits on how many domains can be in SAN certificate. This just makes sure the certificate generated isn't too large.
Path based routes
Path base routes are the same idea as described in the docs for
.lagoon.yml. These are able to be added and removed using the API on a route.This also has a hard coded limit of 10 path based routes per route. This is just an arbitrary limit, as I'm not sure how well used this feature is generally. Maybe it could be made it configurable per project (only configurable by a platform level role)
Annotations
Annotations are also available in the API, these also function the same way as described in the docs. The same restrictions apply.
This also has a hard coded limit of 10 annotations per route. This is just an arbitrary limit, as I'm not sure how well used this feature is generally. Maybe it could be made it configurable per project (only configurable by a platform level role)
Usage
The following describes some basic usage of the routes endpoints, the Lagoon UI will support managing routes, but more advanced options may not be immediately available in the UI.
Creating a Route
When creating a route, you can add it directly to an environment, here is an example of creating a generic route on an environment named
mainpointing to annginxservice. There defaults for fields liketlsAcmeandinsecureif they aren't provided on creation time.This returns the created object, and you can see the defaults for
tlsAcmeandinsecurehere.Updating a route
To change fields on a route, you can update them using the following mutation. In this example, setting
tlsAcmeto false and disabling https redirects.And the return we can see those changes are made.
Deleting a route
To delete a route, you need the route ID. Then run this mutation
Changing which environment a route is attached to
Its possible to move a route from one environment to another. First you have to remove it from the current environment using
removeRouteFromEnvironmentlike soThis will remove the route association from the
mainenvironment, and the route will now be in an unattached state.A deployment of the
mainenvironment will need to be performed now to ensure it is removed from the environment before it is added to the other environment.Once the deployment of the environment is done, you can attach the route to the correct environment using
addOrUpdateRouteOnEnvironmentlike soThis route is now attached to the
devenvironmentA deployment of the
devenvironment will need to be performed for the route to be created in the environment.Autogenerated Routes
By default, autogenerated route configuration on projects and environments is not used. This configuration is only configurable in the
.lagoon.ymlfile. However, as soon as autogenerated route configuration is updated on a project or environment in the API, the autogenerated route config in the.lagoon.ymlfile is ignored.Disable autogenerated routes for the project
If you want to disable all autogenerated routes for a project, updating the autogenerated route configuration on a
And we can see that the enabled state is now false.
If you want to then enable them for a specific environment, you update the autogenerated route configuration for that environment to override the project settings
and we can see the
mainenvironment has autogenerated routes enabledNote
There is no inheritance from the project configuration, this means if you have other settings that are configured in the project autogenerated route configuration, you'll need to add these specific changes to the environment configuration too
Tip
All fields and inputs for these resolvers are available in the API spec.
Other
Limits
There are no limits to how many routes can be added per project, maybe there should be?
Autogenerated and Lagoon YAML routes
Phase 2 support for routes in the API would be updating remote-controller and build-deploy-tool to support sending the non-API created routes back to the API to be visualised, then we can look at deprecating the
routeandroutesfields on an environment forapiRoutesdirectly.Before/After merge
Makefileoverrides forBUILD_DEPLOY_IMAGE_TAGfor feat: support for api routes build-deploy-tool#464